package nl.sportan.samenloop.adapter;

import java.util.List;

import nl.sportan.samenloop.R;
import nl.sportan.samenloop.model.ProgramItem;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ProgramAdapter extends BaseAdapter {

	private Context context;
	private List<ProgramItem> items;
	
	public ProgramAdapter(Context context, List<ProgramItem> items) {
		this.context = context;
		if (items != null) {
			this.items = items;
		}
	}

	
	public int getCount() {
		return items.size();
	}

	public Object getItem(int i) {
		return items.get(i);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ProgramItem m = items.get(position);

		LinearLayout programLayout;

		programLayout = (LinearLayout) LayoutInflater.from(context).inflate(
				R.layout.program_item, parent, false);

		TextView start = (TextView) programLayout.findViewById(R.id.startTime);
		TextView end= (TextView) programLayout.findViewById(R.id.endTime);
		TextView title = (TextView) programLayout.findViewById(R.id.title);
		TextView description = (TextView) programLayout.findViewById(R.id.description);
		
		start.setText(m.getStartTime());
		end.setText(m.getEndTime());
		title.setText(m.getTitle());
		description.setText(m.getDescription());

		return programLayout;
	}

}
